from ..extensions import db
from datetime import datetime


class Admin(db.Model):
    __tablename__ = 'admins'
    
    id = db.Column(db.BigInteger(), primary_key=True, autoincrement=True, comment='管理员ID')
    name = db.Column(db.String(100), nullable=False, comment='姓名')
    gender = db.Column(db.String(1), comment='性别，M=男，F=女')
    email = db.Column(db.String(100), unique=True, nullable=False, comment='邮箱')
    age = db.Column(db.Integer(), comment='年龄')
    password = db.Column(db.String(255), nullable=False, comment='密码')
    phone = db.Column(db.String(20), unique=True, comment='手机号')
    is_enabled = db.Column(db.Boolean, nullable=False, default=True, comment='是否启用，0=禁用，1=启用')
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='记录创建时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'gender': self.gender,
            'email': self.email,
            'phone': self.phone,
            'age': self.age,
            'is_enabled': self.is_enabled,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None
        }